package com.jams.goodox.utils;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.text.Spannable;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.util.Log;

import com.jams.goodox.R;
import com.jams.goodox.constant.Constants;

/**
 * 订单工具类
 * Created by jams on 2017/5/3.
 * ***
 * Tel: ***
 */

public class OrderUtils {
    /**
     * 得到订单状态的信息
     *
     * @return
     */
    public static String getStatus(int status) {
        switch (status) {
            case 0:
                return "待付款";
            case 1:
                return "待接收";
            case 2:
                return "处理中";
            case 3:
                return "待评价";
            case 4:
                return "已完成";
            case 5:
                return "已关闭";
            case 6:
                return "待处理";
        }
        return "";
    }

    //获取订单备注的颜色
    public static SpannableStringBuilder getOrderContent(Context context, String text){
        SpannableStringBuilder spannable = new SpannableStringBuilder(text);//用于可变字符串
        spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(context, R.color.orange)),0,text.indexOf("#",1)+1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return spannable;
    }

    public static boolean isGoodsOrder(String subjectCode) {
        if (subjectCode == null) {
            Log.i("ailee", "Utils.isGoodsOrder 里面有null值");
            return false;
        }
        if (StringUtils.toInt(subjectCode) != Constants.REPAIR_CODE//维修
                && StringUtils.toInt(subjectCode) != Constants.POUR_CODE//投诉表扬
                && StringUtils.toInt(subjectCode) != Constants.RESPONSE_CODE//报事
                && StringUtils.toInt(subjectCode) != Constants.EMS_CODE//快递代寄
                ) {
            return true;
        }
        return false;
    }


    public static String getAfterSale(int code) {
        switch (code) {
            case Constants.Customer_Waiting: // 等待受理
                return "等待受理";
            case Constants.Customer_Return_Good:// 寄回商品
                return "寄回商品";
            case Constants.Customer_Waiting_Receive:// 等待收货
                return "客服收货";
            case Constants.Customer_Waiting_Refund:// 等待退款
                return "等待退款";
            case Constants.Customer_Refund_Complete: // 完成退款
                return "完成退款";
            case Constants.Customer_Cancel_By_user: // 取消申请
                return "已经取消";
            case Constants.Customer_Closed: // 关闭
                return "已经关闭";
            default:
                return "";
        }
    }

    public static String getPayStyle(String style, int status) {

        int payStyle = Utils.getIntByStr(style);
        if (payStyle == 0) {
            return status == 1 ? "线下支付（已付款）" : "线下支付";
        } else if (payStyle == 1) {
            return "支付宝";
        } else if (payStyle == 2) {
            return "银联";
        } else if (payStyle == 3) {
            return "微信";
        } else if (payStyle == 4) {
            return "一网通";
        } else if (payStyle == 5) {
            return "账户余额";
        } else if (payStyle == 9) {
            return "线上支付";
        } else {
            return "账户余额";
        }
    }

    public static String getPayStyle(String style, String status) {
        return getPayStyle(style,Utils.getIntByStr(status));
    }

    public static String getAfterSaleBtnText(int code) {
        switch (code) {
            case Constants.Customer_Waiting: // 等待受理
                return "等待\n受理";
            case Constants.Customer_Return_Good:// 寄回商品
                return "寄回\n商品";
            case Constants.Customer_Waiting_Receive:// 等待收货
                return "客服\n收货";
            case Constants.Customer_Waiting_Refund:// 等待退款
                return "等待\n退款";
            case Constants.Customer_Refund_Complete: // 完成退款
                return "完成\n退款";
            case Constants.Customer_Cancel_By_user: // 取消申请
                return "已经\n取消";
            case Constants.Customer_Closed: // 关闭
                return "已经\n关闭";
            default:
                return "";
        }
    }

    public static String getCustomerType(String type){
        switch (type){
            case Constants.cancelApplyForm:
                return "申请取消订单";
            case Constants.returnGoods:
                return "申请退货";
            default:
                return "";

        }
    }

    public static String getFeel(float f) {
        if (f == 1.0) {
            return "失望";
        } else if (f == 2.0) {
            return "不满";
        } else if (f == 3.0) {
            return "一般";
        } else if (f == 4.0) {
            return "满意";
        } else if (f == 5.0) {
            return "惊喜";
        }
        return "";
    }

    //获取场地订单状态
    public static String getMeetOrderStatus(String status){
        switch (status){
            case "1":
                return "待付款";
            case "2":
                return "已完成";
            case "3":
                return "已关闭";
            default:
                return "";
        }
    }
}
